# Copyright 2020 The XLS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Optimization passes, pass managers.

load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_python//python:proto.bzl", "py_proto_library")
load("@xls_pip_deps//:requirements.bzl", "requirement")
load("//xls/build_rules:py_oss_defs.bzl", "pytype_strict_binary")

# Load proto_library
load(
    "//xls/build_rules:xls_pass_rules.bzl",
    "xls_default_pass_registry",
    "xls_pass",
    "xls_pass_registry",
)
# cc_proto_library is used in this file

package(
    default_applicable_licenses = ["//:license"],
    default_visibility = ["//xls:xls_internal"],
    features = [
        "layering_check",
        "parse_headers",
    ],
    licenses = ["notice"],  # Apache 2.0
)

proto_library(
    name = "optimization_pass_pipeline_proto",
    srcs = ["optimization_pass_pipeline.proto"],
    visibility = ["//xls:xls_users"],
)

cc_proto_library(
    name = "optimization_pass_pipeline_cc_proto",
    visibility = ["//xls:xls_users"],
    deps = [":optimization_pass_pipeline_proto"],
)

py_proto_library(
    name = "optimization_pass_pipeline_py_pb2",
    visibility = ["//xls:xls_users"],
    deps = [":optimization_pass_pipeline_proto"],
)

# Pulls the default pass pipeline out of the toolchain.
xls_default_pass_registry(
    name = "passes",
    tags = ["keep_dep"],
)

xls_pass_registry(
    name = "oss_optimization_passes",
    passes = [
        # TODO(allight): Passes with explicit always-link. Once more explicit
        # configuration is supported these should become xls_pass targets.
        ":bdd_simplification_pass",
        ":conditional_specialization_pass",
        ":inlining_pass",
        ":narrowing_pass",
        ":select_simplification_pass",

        # Normal passes
        ":arith_simplification_pass",
        ":array_simplification_pass",
        ":array_untuple_pass",
        ":basic_simplification_pass",
        ":bdd_cse_pass",
        ":bit_slice_simplification_pass",
        ":boolean_simplification_pass",
        ":canonicalization_pass",
        ":channel_legalization_pass",
        ":comparison_simplification_pass",
        ":concat_simplification_pass",
        ":constant_folding_pass",
        ":cse_pass",
        ":dataflow_simplification_pass",
        ":dce_pass",
        ":dfe_pass",
        ":identity_removal_pass",
        ":label_recovery_pass",
        ":lut_conversion_pass",
        ":map_inlining_pass",
        ":next_value_optimization_pass",
        ":non_synth_separation_pass",
        ":proc_state_array_flattening_pass",
        ":proc_state_bits_shattering_pass",
        ":proc_state_narrowing_pass",
        ":proc_state_optimization_pass",
        ":proc_state_provenance_narrowing_pass",
        ":proc_state_tuple_flattening_pass",
        ":ram_rewrite_pass",
        ":reassociation_pass",
        ":receive_default_value_simplification_pass",
        ":resource_sharing_pass",
        ":select_lifting_pass",
        ":select_merging_pass",
        ":sparsify_select_pass",
        ":strength_reduction_pass",
        ":table_switch_pass",
        ":token_dependency_pass",
        ":token_simplification_pass",
        ":unroll_pass",
        ":useless_assert_removal_pass",
        ":useless_io_removal_pass",
    ],
    pipeline = "optimization_pass_pipeline.txtpb",
    tags = ["keep_dep"],
)

proto_library(
    name = "pass_pipeline_proto",
    srcs = ["pass_pipeline.proto"],
    visibility = ["//xls:xls_users"],
)

cc_proto_library(
    name = "pass_pipeline_cc_proto",
    visibility = ["//xls:xls_users"],
    deps = [":pass_pipeline_proto"],
)

py_proto_library(
    name = "pass_pipeline_py_pb2",
    visibility = ["//xls:xls_users"],
    deps = [":pass_pipeline_proto"],
)

cc_binary(
    name = "dump_default_optimization_pass_pipeline_main",
    srcs = ["dump_default_optimization_pass_pipeline_main.cc"],
    visibility = ["//visibility:private"],
    deps = [
        ":optimization_pass",
        ":optimization_pass_pipeline",
        ":pass_pipeline_cc_proto",
        ":passes",
        "//xls/common:exit_status",
        "//xls/common:init_xls",
        "//xls/common/file:filesystem",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_protobuf//:protobuf",
    ],
)

genrule(
    name = "default_optimization_pipeline_proto",
    outs = ["default_opt_pass_pipeline.binarypb"],
    cmd = "$(location :dump_default_optimization_pass_pipeline_main) --proto_out $@",
    tools = [":dump_default_optimization_pass_pipeline_main"],
)

genrule(
    name = "default_optimization_pipeline_textproto",
    outs = ["default_opt_pass_pipeline.textpb"],
    cmd = "$(location :dump_default_optimization_pass_pipeline_main) --textproto_out $@",
    tools = [":dump_default_optimization_pass_pipeline_main"],
)

proto_library(
    name = "pass_metrics_proto",
    srcs = ["pass_metrics.proto"],
    deps = [
        "//xls/ir:transform_metrics_proto",
        "@com_google_protobuf//:duration_proto",
    ],
)

cc_proto_library(
    name = "pass_metrics_cc_proto",
    deps = [":pass_metrics_proto"],
)

py_proto_library(
    name = "pass_metrics_py_pb2",
    deps = [":pass_metrics_proto"],
)

cc_library(
    name = "optimization_pass_pipeline",
    srcs = ["optimization_pass_pipeline.cc"],
    hdrs = ["optimization_pass_pipeline.h"],
    deps = [
        ":optimization_pass",
        ":optimization_pass_registry",
        ":pass_base",
        ":pipeline_generator",
        ":query_engine_checker",
        ":verifier_checker",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "verifier_checker",
    srcs = ["verifier_checker.cc"],
    hdrs = ["verifier_checker.h"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/ir",
        "//xls/ir:verifier",
        "@com_google_absl//absl/status",
    ],
)

cc_library(
    name = "query_engine_checker",
    srcs = ["query_engine_checker.cc"],
    hdrs = ["query_engine_checker.h"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "@com_google_absl//absl/status",
    ],
)

cc_test(
    name = "optimization_pass_test",
    srcs = ["optimization_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common:casts",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_parser",
        "//xls/ir:ram_rewrite_cc_proto",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "identity_removal_pass_test",
    srcs = ["identity_removal_pass_test.cc"],
    deps = [
        ":dce_pass",
        ":identity_removal_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "arith_simplification_pass_test",
    srcs = ["arith_simplification_pass_test.cc"],
    shard_count = 10,
    deps = [
        ":arith_simplification_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:math_util",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_test_utils",
        "//xls/ir:events",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "optimization_pass_pipeline_test",
    srcs = ["optimization_pass_pipeline_test.cc"],
    deps = [
        ":optimization_pass",
        ":optimization_pass_pipeline",
        ":pass_base",
        ":passes",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/examples:sample_packages",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:value",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "canonicalization_pass_test",
    srcs = ["canonicalization_pass_test.cc"],
    deps = [
        ":canonicalization_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:events",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:value",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

xls_pass(
    name = "unroll_pass",
    srcs = ["unroll_pass.cc"],
    hdrs = ["unroll_pass.h"],
    pass_class = "UnrollPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:value",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "unroll_pass_test",
    srcs = ["unroll_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":unroll_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_parser",
        "@googletest//:gtest",
    ],
)

# TODO(allight): Multiple configurations prevents xls_pass
# buildozer: disable=alwayslink-with-hdrs
cc_library(
    name = "inlining_pass",
    srcs = ["inlining_pass.cc"],
    hdrs = ["inlining_pass.h"],
    deps = [
        ":optimization_pass",
        ":optimization_pass_registry",
        ":pass_base",
        "//xls/common:module_initializer",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:source_location",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
    # Temporary until pipeline changes are further along.
    alwayslink = 1,
)

xls_pass(
    name = "map_inlining_pass",
    srcs = ["map_inlining_pass.cc"],
    hdrs = ["map_inlining_pass.h"],
    pass_class = "MapInliningPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:value",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "map_inlining_pass_test",
    srcs = ["map_inlining_pass_test.cc"],
    deps = [
        ":map_inlining_pass",
        ":optimization_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_parser",
        "//xls/ir:ir_test_base",
        "@com_google_absl//absl/log",
        "@googletest//:gtest",
    ],
)

xls_pass(
    name = "cse_pass",
    srcs = ["cse_pass.cc"],
    hdrs = ["cse_pass.h"],
    pass_class = "CsePass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/hash",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "constant_folding_pass",
    srcs = ["constant_folding_pass.cc"],
    hdrs = ["constant_folding_pass.h"],
    pass_class = "ConstantFoldingPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        "//xls/common/status:status_macros",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:op",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
    ],
)

xls_pass(
    name = "bit_slice_simplification_pass",
    srcs = ["bit_slice_simplification_pass.cc"],
    hdrs = ["bit_slice_simplification_pass.h"],
    pass_class = "BitSliceSimplificationPass",
    deps = [
        ":lazy_ternary_query_engine",
        ":optimization_pass",
        ":partial_info_query_engine",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        ":union_query_engine",
        "//xls/common:math_util",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "concat_simplification_pass",
    srcs = ["concat_simplification_pass.cc"],
    hdrs = ["concat_simplification_pass.h"],
    pass_class = "ConcatSimplificationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:value",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "boolean_simplification_pass",
    srcs = ["boolean_simplification_pass.cc"],
    hdrs = ["boolean_simplification_pass.h"],
    pass_class = "BooleanSimplificationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:format_preference",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "arith_simplification_pass",
    srcs = ["arith_simplification_pass.cc"],
    hdrs = ["arith_simplification_pass.h"],
    pass_class = "ArithSimplificationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:inline_bitmap",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:big_int",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:ternary",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:fixed_array",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "dfe_pass",
    srcs = ["dfe_pass.cc"],
    hdrs = ["dfe_pass.h"],
    pass_class = "DeadFunctionEliminationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:proc_elaboration",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
    ],
)

xls_pass(
    name = "canonicalization_pass",
    srcs = ["canonicalization_pass.cc"],
    hdrs = ["canonicalization_pass.h"],
    pass_class = "CanonicalizationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:value",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "optimization_pass",
    srcs = ["optimization_pass.cc"],
    hdrs = ["optimization_pass.h"],
    deps = [
        ":pass_base",
        ":pass_pipeline_cc_proto",
        ":pass_registry",
        ":pipeline_generator",
        ":query_engine",
        ":query_engine_helpers",
        "//xls/common:math_util",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:change_listener",
        "//xls/ir:ram_rewrite_cc_proto",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:nullability",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/hash",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "optimization_pass_registry",
    srcs = ["optimization_pass_registry.cc"],
    hdrs = ["optimization_pass_registry.h"],
    deps = [
        ":optimization_pass",
        ":optimization_pass_pipeline_cc_proto",
        ":pipeline_generator",
        "//xls/common:module_initializer",
        "//xls/common:source_location",
        "//xls/common/status:status_macros",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "identity_removal_pass",
    srcs = ["identity_removal_pass.cc"],
    hdrs = ["identity_removal_pass.h"],
    pass_class = "IdentityRemovalPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:op",
        "@com_google_absl//absl/status:statusor",
    ],
)

xls_pass(
    name = "dce_pass",
    srcs = ["dce_pass.cc"],
    hdrs = ["dce_pass.h"],
    pass_class = "DeadCodeEliminationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
    ],
)

xls_pass(
    name = "token_dependency_pass",
    srcs = ["token_dependency_pass.cc"],
    hdrs = ["token_dependency_pass.h"],
    pass_class = "TokenDependencyPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":token_provenance_analysis",
        "//xls/common/logging:log_lines",
        "//xls/common/status:status_macros",
        "//xls/data_structures:transitive_closure",
        "//xls/ir",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

xls_pass(
    name = "token_simplification_pass",
    srcs = ["token_simplification_pass.cc"],
    hdrs = ["token_simplification_pass.h"],
    pass_class = "TokenSimplificationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "strength_reduction_pass",
    srcs = ["strength_reduction_pass.cc"],
    hdrs = ["strength_reduction_pass.h"],
    pass_class = "StrengthReductionPass",
    deps = [
        ":lazy_ternary_query_engine",
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        ":union_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "range_query_engine",
    srcs = ["range_query_engine.cc"],
    hdrs = ["range_query_engine.h"],
    deps = [
        ":query_engine",
        "//xls/common:math_util",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:interval",
        "//xls/ir:interval_ops",
        "//xls/ir:interval_set",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/hash",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "back_propagate_range_analysis",
    srcs = ["back_propagate_range_analysis.cc"],
    hdrs = ["back_propagate_range_analysis.h"],
    deps = [
        ":range_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:interval",
        "//xls/ir:interval_ops",
        "//xls/ir:interval_set",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:type",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "context_sensitive_range_query_engine",
    srcs = ["context_sensitive_range_query_engine.cc"],
    hdrs = ["context_sensitive_range_query_engine.h"],
    deps = [
        ":back_propagate_range_analysis",
        ":node_dependency_analysis",
        ":predicate_state",
        ":query_engine",
        ":range_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:inline_bitmap",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:interval",
        "//xls/ir:interval_ops",
        "//xls/ir:interval_set",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

cc_library(
    name = "ternary_query_engine",
    srcs = ["ternary_query_engine.cc"],
    hdrs = ["ternary_query_engine.h"],
    deps = [
        ":query_engine",
        ":ternary_evaluator",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:abstract_node_evaluator",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "stateless_query_engine",
    srcs = ["stateless_query_engine.cc"],
    hdrs = ["stateless_query_engine.h"],
    deps = [
        ":query_engine",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

cc_library(
    name = "union_query_engine",
    srcs = ["union_query_engine.cc"],
    hdrs = ["union_query_engine.h"],
    deps = [
        ":predicate_state",
        ":query_engine",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:interval_set",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "folding_graph",
    srcs = ["folding_graph.cc"],
    hdrs = ["folding_graph.h"],
    deps = [
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:op",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/types:span",
        "@com_google_ortools//ortools/graph",
        "@com_google_ortools//ortools/graph:cliques",
    ],
)

xls_pass(
    name = "resource_sharing_pass",
    srcs = ["resource_sharing_pass.cc"],
    hdrs = ["resource_sharing_pass.h"],
    pass_class = "ResourceSharingPass",
    deps = [
        ":bdd_query_engine",
        ":folding_graph",
        ":node_dependency_analysis",
        ":optimization_pass",
        ":pass_base",
        ":post_dominator_analysis",
        ":query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/estimators/area_model:area_estimator",
        "//xls/estimators/area_model:area_estimators",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:op",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/random",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

xls_pass(
    name = "select_lifting_pass",
    srcs = ["select_lifting_pass.cc"],
    hdrs = ["select_lifting_pass.h"],
    pass_class = "SelectLiftingPass",
    deps = [
        ":critical_path_delay_analysis",
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "select_merging_pass",
    srcs = ["select_merging_pass.cc"],
    hdrs = ["select_merging_pass.h"],
    pass_class = "SelectMergingPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

# TODO(allight): 2 different passes in single library.
# buildozer: disable=alwayslink-with-hdrs
cc_library(
    name = "select_simplification_pass",
    srcs = ["select_simplification_pass.cc"],
    hdrs = ["select_simplification_pass.h"],
    deps = [
        ":bit_provenance_analysis",
        ":lazy_ternary_query_engine",
        ":optimization_pass",
        ":optimization_pass_registry",
        ":partial_info_query_engine",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        ":union_query_engine",
        "//xls/common:visitor",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:algorithm",
        "//xls/data_structures:inline_bitmap",
        "//xls/data_structures:leaf_type_tree",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:interval_ops",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:fixed_array",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/log:vlog_is_on",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_absl//absl/types:variant",
    ],
    # Temporary until pipeline changes are further along.
    alwayslink = 1,
)

xls_pass(
    name = "sparsify_select_pass",
    srcs = ["sparsify_select_pass.cc"],
    hdrs = ["sparsify_select_pass.h"],
    pass_class = "SparsifySelectPass",
    deps = [
        ":optimization_pass",
        ":partial_info_query_engine",
        ":pass_base",
        ":query_engine",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:interval",
        "//xls/ir:interval_set",
        "//xls/ir:op",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "ternary_evaluator",
    hdrs = ["ternary_evaluator.h"],
    deps = [
        "//xls/ir:abstract_evaluator",
        "//xls/ir:ternary",
        "@com_google_absl//absl/log",
    ],
)

cc_library(
    name = "dataflow_dominator_analysis",
    srcs = ["dataflow_dominator_analysis.cc"],
    hdrs = ["dataflow_dominator_analysis.h"],
    deps = [
        "//xls/common/status:ret_check",
        "//xls/ir",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "dataflow_graph_analysis",
    srcs = ["dataflow_graph_analysis.cc"],
    hdrs = ["dataflow_graph_analysis.h"],
    deps = [
        ":query_engine",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_ortools//ortools/graph",
        "@com_google_ortools//ortools/graph:generic_max_flow",
    ],
)

cc_library(
    name = "post_dominator_analysis",
    srcs = ["post_dominator_analysis.cc"],
    hdrs = ["post_dominator_analysis.h"],
    deps = [
        "//xls/common/status:ret_check",
        "//xls/ir",
        "//xls/ir:node_util",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "predicate_state",
    hdrs = ["predicate_state.h"],
    deps = [
        "//xls/common:visitor",
        "//xls/common/status:ret_check",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:interval",
        "//xls/ir:interval_ops",
        "//xls/ir:interval_set",
        "//xls/ir:ternary",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_absl//absl/types:variant",
    ],
)

cc_library(
    name = "predicate_dominator_analysis",
    srcs = ["predicate_dominator_analysis.cc"],
    hdrs = ["predicate_dominator_analysis.h"],
    deps = [
        ":predicate_state",
        "//xls/common:strong_int",
        "//xls/ir",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
    ],
)

cc_library(
    name = "token_provenance_analysis",
    srcs = ["token_provenance_analysis.cc"],
    hdrs = ["token_provenance_analysis.h"],
    deps = [
        ":dataflow_visitor",
        "//xls/common/logging:log_lines",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:op",
        "//xls/ir:type",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "bdd_evaluator",
    hdrs = ["bdd_evaluator.h"],
    deps = [
        "//xls/data_structures:binary_decision_diagram",
        "//xls/ir:abstract_evaluator",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log:check",
    ],
)

cc_library(
    name = "node_dependency_analysis",
    srcs = ["node_dependency_analysis.cc"],
    hdrs = ["node_dependency_analysis.h"],
    deps = [
        ":lazy_dag_cache",
        ":lazy_node_data",
        "//xls/ir",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "node_dependency_analysis_test",
    srcs = ["node_dependency_analysis_test.cc"],
    deps = [
        ":node_dependency_analysis",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:benchmark_support",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings:str_format",
        "@google_benchmark//:benchmark",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "query_engine",
    srcs = ["query_engine.cc"],
    hdrs = [
        "forwarding_query_engine.h",
        "query_engine.h",
    ],
    deps = [
        ":predicate_state",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:interval_ops",
        "//xls/ir:interval_set",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

cc_library(
    name = "lazy_dag_cache",
    hdrs = ["lazy_dag_cache.h"],
    deps = [
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "lazy_node_data",
    hdrs = ["lazy_node_data.h"],
    deps = [
        ":lazy_dag_cache",
        ":query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:change_listener",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "lazy_node_info",
    hdrs = [
        "lazy_node_info.h",
    ],
    deps = [
        ":lazy_dag_cache",
        ":lazy_node_data",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:type",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "critical_path_delay_analysis",
    srcs = ["critical_path_delay_analysis.cc"],
    hdrs = ["critical_path_delay_analysis.h"],
    deps = [
        ":lazy_dag_cache",
        ":lazy_node_data",
        ":optimization_pass",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/ir",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "critical_path_delay_analysis_test",
    srcs = ["critical_path_delay_analysis_test.cc"],
    deps = [
        ":critical_path_delay_analysis",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "critical_path_slack_analysis",
    srcs = ["critical_path_slack_analysis.cc"],
    hdrs = ["critical_path_slack_analysis.h"],
    deps = [
        ":critical_path_delay_analysis",
        ":lazy_dag_cache",
        ":lazy_node_data",
        "//xls/ir",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "critical_path_slack_analysis_test",
    srcs = ["critical_path_slack_analysis_test.cc"],
    deps = [
        ":critical_path_delay_analysis",
        ":critical_path_slack_analysis",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "visibility_analysis",
    srcs = ["visibility_analysis.cc"],
    hdrs = ["visibility_analysis.h"],
    deps = [
        ":bdd_evaluator",
        ":bdd_query_engine",
        ":lazy_dag_cache",
        ":lazy_node_data",
        ":node_dependency_analysis",
        ":query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:binary_decision_diagram",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:change_listener",
        "//xls/ir:op",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "visibility_analysis_test",
    srcs = ["visibility_analysis_test.cc"],
    deps = [
        ":bdd_evaluator",
        ":bdd_query_engine",
        ":node_dependency_analysis",
        ":query_engine",
        ":visibility_analysis",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/data_structures:binary_decision_diagram",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "lazy_query_engine",
    hdrs = [
        "lazy_query_engine.h",
    ],
    deps = [
        ":lazy_dag_cache",
        ":lazy_node_info",
        ":query_engine",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:change_listener",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "lazy_ternary_query_engine",
    srcs = ["lazy_ternary_query_engine.cc"],
    hdrs = ["lazy_ternary_query_engine.h"],
    deps = [
        ":dataflow_visitor",
        ":lazy_query_engine",
        ":query_engine",
        ":ternary_evaluator",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:interval",
        "//xls/ir:interval_ops",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

cc_test(
    name = "lazy_ternary_query_engine_test",
    srcs = ["lazy_ternary_query_engine_test.cc"],
    deps = [
        ":lazy_ternary_query_engine",
        ":query_engine",
        ":ternary_query_engine_test_common",
        "//xls/common:visitor",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:benchmark_support",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:source_location",
        "//xls/ir:ternary",
        "//xls/ir:value",
        "//xls/ir:value_builder",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_absl//absl/types:variant",
        "@google_benchmark//:benchmark",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "partial_info_query_engine",
    srcs = ["partial_info_query_engine.cc"],
    hdrs = ["partial_info_query_engine.h"],
    deps = [
        ":dataflow_visitor",
        ":lazy_query_engine",
        ":query_engine",
        "//xls/common:math_util",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:interval",
        "//xls/ir:interval_ops",
        "//xls/ir:interval_set",
        "//xls/ir:op",
        "//xls/ir:partial_info",
        "//xls/ir:partial_ops",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

cc_test(
    name = "partial_info_query_engine_test",
    srcs = ["partial_info_query_engine_test.cc"],
    deps = [
        ":partial_info_query_engine",
        ":query_engine",
        ":range_query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/data_structures:leaf_type_tree",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/fuzzer/ir_fuzzer:query_engine_helpers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:function_builder",
        "//xls/ir:interval",
        "//xls/ir:interval_set",
        "//xls/ir:interval_set_test_utils",
        "//xls/ir:ir_test_base",
        "//xls/ir:partial_info",
        "//xls/ir:partial_ops",
        "//xls/ir:ternary",
        "//xls/ir:value",
        "//xls/ir:value_builder",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "bdd_query_engine",
    srcs = ["bdd_query_engine.cc"],
    hdrs = ["bdd_query_engine.h"],
    deps = [
        ":bdd_evaluator",
        ":lazy_query_engine",
        ":predicate_state",
        ":query_engine",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/data_structures:binary_decision_diagram",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:abstract_evaluator",
        "//xls/ir:abstract_node_evaluator",
        "//xls/ir:bits",
        "//xls/ir:interval",
        "//xls/ir:interval_set",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

cc_test(
    name = "bdd_query_engine_test",
    srcs = ["bdd_query_engine_test.cc"],
    deps = [
        ":bdd_query_engine",
        ":query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:interval",
        "//xls/ir:interval_set",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "@googletest//:gtest",
    ],
)

# TODO(allight): Multiple configurations prevent xls_pass
# buildozer: disable=alwayslink-with-hdrs
cc_library(
    name = "bdd_simplification_pass",
    srcs = ["bdd_simplification_pass.cc"],
    hdrs = ["bdd_simplification_pass.h"],
    deps = [
        ":bdd_query_engine",
        ":optimization_pass",
        ":optimization_pass_registry",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        ":union_query_engine",
        "//xls/common:module_initializer",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:format_preference",
        "//xls/ir:function_builder",
        "//xls/ir:op",
        "//xls/ir:value",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/log:vlog_is_on",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
    # Temporary until pipeline changes are further along.
    alwayslink = 1,
)

cc_library(
    name = "pass_base",
    srcs = ["pass_base.cc"],
    hdrs = ["pass_base.h"],
    deps = [
        ":pass_metrics_cc_proto",
        ":pass_pipeline_cc_proto",
        "//xls/common:stopwatch",
        "//xls/common/file:filesystem",
        "//xls/common/logging:log_lines",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/passes/tools:passes_profile",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@com_google_protobuf//:duration_cc_proto",
    ],
)

cc_test(
    name = "pass_base_test",
    srcs = ["pass_base_test.cc"],
    deps = [
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/file:filesystem",
        "//xls/common/file:temp_directory",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "pass_registry",
    hdrs = ["pass_registry.h"],
    deps = [
        ":pass_base",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/synchronization",
    ],
)

cc_library(
    name = "pipeline_generator",
    hdrs = ["pipeline_generator.h"],
    deps = [
        ":pass_base",
        ":pass_pipeline_cc_proto",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test(
    name = "pipeline_generator_test",
    srcs = ["pipeline_generator_test.cc"],
    deps = [
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        ":pass_pipeline_cc_proto",
        ":pipeline_generator",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_protobuf//:protobuf",
        "@googletest//:gtest",
        "@re2",
    ],
)

cc_test(
    name = "predicate_state_test",
    srcs = ["predicate_state_test.cc"],
    deps = [
        ":predicate_state",
        "//xls/common:xls_gunit_main",
        "//xls/ir",
        "//xls/ir:function_builder",
        "@com_google_absl//absl/hash",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

# TODO(allight): Multiple configurations prevent xls_pass
# buildozer: disable=alwayslink-with-hdrs
cc_library(
    name = "narrowing_pass",
    srcs = ["narrowing_pass.cc"],
    hdrs = ["narrowing_pass.h"],
    deps = [
        ":aliasing_query_engine",
        ":bit_count_query_engine",
        ":context_sensitive_range_query_engine",
        ":lazy_ternary_query_engine",
        ":optimization_pass",
        ":optimization_pass_registry",
        ":partial_info_query_engine",
        ":pass_base",
        ":predicate_dominator_analysis",
        ":predicate_state",
        ":proc_state_range_query_engine",
        ":query_engine",
        ":stateless_query_engine",
        ":union_query_engine",
        "//xls/common:math_util",
        "//xls/common:module_initializer",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:inline_bitmap",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:interval",
        "//xls/ir:interval_set",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/log:vlog_is_on",
        "@com_google_absl//absl/numeric:int128",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
    # Temporary until pipeline changes are further along.
    alwayslink = 1,
)

xls_pass(
    name = "bdd_cse_pass",
    srcs = ["bdd_cse_pass.cc"],
    hdrs = ["bdd_cse_pass.h"],
    pass_class = "BddCsePass",
    deps = [
        ":bdd_query_engine",
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/estimators/delay_model:delay_estimators",
        "//xls/ir",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/hash",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
    ],
)

xls_pass(
    name = "label_recovery_pass",
    srcs = ["label_recovery_pass.cc"],
    hdrs = ["label_recovery_pass.h"],
    pass_class = "LabelRecoveryPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common:visitor",
        "//xls/ir",
        "//xls/ir:op",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:variant",
    ],
)

cc_test(
    name = "label_recovery_pass_test",
    srcs = ["label_recovery_pass_test.cc"],
    deps = [
        ":dfe_pass",
        ":inlining_pass",
        ":label_recovery_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:ir_parser",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

xls_pass(
    name = "reassociation_pass",
    srcs = ["reassociation_pass.cc"],
    hdrs = ["reassociation_pass.h"],
    pass_class = "ReassociationPass",
    deps = [
        ":bit_count_query_engine",
        ":lazy_dag_cache",
        ":lazy_node_info",
        ":lazy_ternary_query_engine",
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        ":ternary_evaluator",
        ":union_query_engine",
        "//xls/common:math_util",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:change_listener",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

xls_pass(
    name = "table_switch_pass",
    srcs = ["table_switch_pass.cc"],
    hdrs = ["table_switch_pass.h"],
    pass_class = "TableSwitchPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:op",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/log:vlog_is_on",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "array_simplification_pass",
    srcs = ["array_simplification_pass.cc"],
    hdrs = ["array_simplification_pass.h"],
    pass_class = "ArraySimplificationPass",
    deps = [
        ":lazy_ternary_query_engine",
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        ":union_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:interval_set",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "useless_assert_removal_pass",
    srcs = ["useless_assert_removal_pass.cc"],
    hdrs = ["useless_assert_removal_pass.h"],
    pass_class = "UselessAssertRemovalPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":stateless_query_engine",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:op",
        "@com_google_absl//absl/status:statusor",
    ],
)

xls_pass(
    name = "useless_io_removal_pass",
    srcs = ["useless_io_removal_pass.cc"],
    hdrs = ["useless_io_removal_pass.h"],
    pass_class = "UselessIORemovalPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":stateless_query_engine",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status:statusor",
    ],
)

xls_pass(
    name = "comparison_simplification_pass",
    srcs = ["comparison_simplification_pass.cc"],
    hdrs = ["comparison_simplification_pass.h"],
    pass_class = "ComparisonSimplificationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:interval",
        "//xls/ir:interval_set",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

# TODO(allight): Multiple configurations prevent xls_pass
# buildozer: disable=alwayslink-with-hdrs
cc_library(
    name = "conditional_specialization_pass",
    srcs = ["conditional_specialization_pass.cc"],
    hdrs = ["conditional_specialization_pass.h"],
    deps = [
        ":bdd_query_engine",
        ":optimization_pass",
        ":optimization_pass_registry",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        ":union_query_engine",
        "//xls/common:module_initializer",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:inline_bitmap",
        "//xls/data_structures:leaf_type_tree",
        "//xls/data_structures:transitive_closure",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:interval",
        "//xls/ir:interval_ops",
        "//xls/ir:interval_set",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:partial_info",
        "//xls/ir:partial_ops",
        "//xls/ir:source_location",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
    # Temporary until pipeline changes are further along.
    alwayslink = 1,
)

xls_pass(
    name = "proc_state_narrowing_pass",
    srcs = ["proc_state_narrowing_pass.cc"],
    hdrs = ["proc_state_narrowing_pass.h"],
    pass_class = "ProcStateNarrowingPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":proc_state_range_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:interval_ops",
        "//xls/ir:op",
        "//xls/ir:state_element",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "proc_state_narrowing_pass_test",
    srcs = ["proc_state_narrowing_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":proc_state_narrowing_pass",
        ":proc_state_optimization_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

xls_pass(
    name = "proc_state_optimization_pass",
    srcs = ["proc_state_optimization_pass.cc"],
    hdrs = ["proc_state_optimization_pass.h"],
    pass_class = "ProcStateOptimizationPass",
    deps = [
        ":dataflow_visitor",
        ":lazy_ternary_query_engine",
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        ":union_query_engine",
        "//xls/common:math_util",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:inline_bitmap",
        "//xls/data_structures:leaf_type_tree",
        "//xls/data_structures:transitive_closure",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:state_element",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/log:vlog_is_on",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

xls_pass(
    name = "proc_state_tuple_flattening_pass",
    srcs = ["proc_state_tuple_flattening_pass.cc"],
    hdrs = ["proc_state_tuple_flattening_pass.h"],
    pass_class = "ProcStateTupleFlatteningPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:state_element",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "proc_state_array_flattening_pass",
    srcs = ["proc_state_array_flattening_pass.cc"],
    hdrs = ["proc_state_array_flattening_pass.h"],
    pass_class = "ProcStateArrayFlatteningPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common:math_util",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:state_element",
        "//xls/ir:value",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

xls_pass(
    name = "proc_state_bits_shattering_pass",
    srcs = ["proc_state_bits_shattering_pass.cc"],
    hdrs = ["proc_state_bits_shattering_pass.h"],
    pass_class = "ProcStateBitsShatteringPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:op",
        "//xls/ir:state_element",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

xls_pass(
    name = "ram_rewrite_pass",
    srcs = ["ram_rewrite_pass.cc"],
    hdrs = ["ram_rewrite_pass.h"],
    pass_class = "RamRewritePass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "ram_rewrite_pass_test",
    srcs = ["ram_rewrite_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":optimization_pass_pipeline",
        ":pass_base",
        ":passes",
        ":ram_rewrite_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "dataflow_visitor",
    hdrs = ["dataflow_visitor.h"],
    deps = [
        ":stateless_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:type",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "receive_default_value_simplification_pass",
    srcs = ["receive_default_value_simplification_pass.cc"],
    hdrs = ["receive_default_value_simplification_pass.h"],
    pass_class = "ReceiveDefaultValueSimplificationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:node_util",
        "//xls/ir:value",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "receive_default_value_simplification_pass_test",
    srcs = ["receive_default_value_simplification_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":receive_default_value_simplification_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "proc_state_array_flattening_pass_test",
    srcs = ["proc_state_array_flattening_pass_test.cc"],
    deps = [
        ":constant_folding_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        ":proc_state_array_flattening_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "proc_state_bits_shattering_pass_test",
    srcs = ["proc_state_bits_shattering_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":proc_state_bits_shattering_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:state_element",
        "//xls/ir:value",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "proc_state_tuple_flattening_pass_test",
    srcs = ["proc_state_tuple_flattening_pass_test.cc"],
    deps = [
        ":dataflow_simplification_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        ":proc_state_tuple_flattening_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "proc_state_optimization_pass_test",
    srcs = ["proc_state_optimization_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":proc_state_optimization_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "inlining_pass_test",
    srcs = ["inlining_pass_test.cc"],
    deps = [
        ":dce_pass",
        ":inlining_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "cse_pass_test",
    srcs = ["cse_pass_test.cc"],
    deps = [
        ":cse_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "constant_folding_pass_test",
    srcs = ["constant_folding_pass_test.cc"],
    deps = [
        ":constant_folding_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "bit_slice_simplification_pass_test",
    srcs = ["bit_slice_simplification_pass_test.cc"],
    deps = [
        ":bit_slice_simplification_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:events",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "boolean_simplification_pass_test",
    srcs = ["boolean_simplification_pass_test.cc"],
    deps = [
        ":boolean_simplification_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "concat_simplification_pass_test",
    srcs = ["concat_simplification_pass_test.cc"],
    deps = [
        ":bdd_cse_pass",
        ":bit_slice_simplification_pass",
        ":concat_simplification_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "token_dependency_pass_test",
    srcs = ["token_dependency_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":token_dependency_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "token_simplification_pass_test",
    srcs = ["token_simplification_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":token_simplification_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "strength_reduction_pass_test",
    srcs = ["strength_reduction_pass_test.cc"],
    deps = [
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        ":strength_reduction_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/solvers:z3_ir_equivalence",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "//xls/solvers:z3_ir_translator",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "ternary_query_engine_test",
    srcs = ["ternary_query_engine_test.cc"],
    deps = [
        ":ternary_query_engine",
        ":ternary_query_engine_test_common",
        "//xls/common:visitor",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:benchmark_support",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:source_location",
        "//xls/ir:ternary",
        "//xls/ir:value",
        "//xls/ir:value_builder",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_absl//absl/types:variant",
        "@google_benchmark//:benchmark",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "stateless_query_engine_test",
    srcs = ["stateless_query_engine_test.cc"],
    deps = [
        ":stateless_query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "@com_google_absl//absl/log",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "select_merging_pass_test",
    srcs = ["select_merging_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":select_merging_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "select_simplification_pass_test",
    srcs = ["select_simplification_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":select_simplification_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "ternary_evaluator_test",
    srcs = ["ternary_evaluator_test.cc"],
    deps = [
        ":ternary_evaluator",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:ternary",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "dce_pass_test",
    srcs = ["dce_pass_test.cc"],
    deps = [
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "predicate_dominator_analysis_test",
    srcs = ["predicate_dominator_analysis_test.cc"],
    deps = [
        ":predicate_dominator_analysis",
        ":predicate_state",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:benchmark_support",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "@google_benchmark//:benchmark",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "dataflow_dominator_analysis_test",
    srcs = ["dataflow_dominator_analysis_test.cc"],
    deps = [
        ":dataflow_dominator_analysis",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "dataflow_graph_analysis_test",
    srcs = ["dataflow_graph_analysis_test.cc"],
    deps = [
        ":dataflow_graph_analysis",
        ":ternary_query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "post_dominator_analysis_test",
    srcs = ["post_dominator_analysis_test.cc"],
    deps = [
        ":post_dominator_analysis",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "token_provenance_analysis_test",
    srcs = ["token_provenance_analysis_test.cc"],
    deps = [
        ":token_provenance_analysis",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "query_engine_test",
    srcs = ["query_engine_test.cc"],
    deps = [
        ":bdd_query_engine",
        ":predicate_state",
        ":query_engine",
        ":ternary_query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:format_preference",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:ternary",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "union_query_engine_test",
    srcs = ["union_query_engine_test.cc"],
    deps = [
        ":query_engine",
        ":union_query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:interval",
        "//xls/ir:interval_set",
        "//xls/ir:ir_test_base",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "bdd_simplification_pass_test",
    srcs = ["bdd_simplification_pass_test.cc"],
    deps = [
        ":bdd_simplification_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "narrowing_pass_test",
    srcs = ["narrowing_pass_test.cc"],
    deps = [
        ":narrowing_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/logging:scoped_vlog_level",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/base:log_severity",
        "@com_google_absl//absl/log:scoped_mock_log",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "dfe_pass_test",
    srcs = ["dfe_pass_test.cc"],
    deps = [
        ":dfe_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "bdd_cse_pass_test",
    srcs = ["bdd_cse_pass_test.cc"],
    deps = [
        ":bdd_cse_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "range_query_engine_test",
    srcs = ["range_query_engine_test.cc"],
    deps = [
        ":range_query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:function_builder",
        "//xls/ir:interval",
        "//xls/ir:interval_ops",
        "//xls/ir:interval_set",
        "//xls/ir:interval_set_test_utils",
        "//xls/ir:ir_test_base",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_builder",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "back_propagate_range_analysis_test",
    srcs = ["back_propagate_range_analysis_test.cc"],
    deps = [
        ":back_propagate_range_analysis",
        ":range_query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:interval",
        "//xls/ir:interval_set",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "context_sensitive_range_query_engine_test",
    srcs = ["context_sensitive_range_query_engine_test.cc"],
    deps = [
        ":context_sensitive_range_query_engine",
        ":predicate_state",
        ":query_engine",
        ":range_query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/data_structures:leaf_type_tree",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:function_builder",
        "//xls/ir:interval",
        "//xls/ir:interval_set",
        "//xls/ir:ir_test_base",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value_builder",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "reassociation_pass_test",
    srcs = ["reassociation_pass_test.cc"],
    shard_count = 10,
    deps = [
        ":arith_simplification_pass",
        ":basic_simplification_pass",
        ":bit_slice_simplification_pass",
        ":constant_folding_pass",
        ":dce_pass",
        ":narrowing_pass",
        ":optimization_pass",
        ":pass_base",
        ":pass_test_helpers",
        ":reassociation_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_parser",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:verifier",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "array_simplification_pass_test",
    srcs = ["array_simplification_pass_test.cc"],
    deps = [
        ":array_simplification_pass",
        ":constant_folding_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_parser",
        "//xls/ir:ir_test_base",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "table_switch_pass_test",
    srcs = ["table_switch_pass_test.cc"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":table_switch_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:events",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "useless_assert_removal_pass_test",
    srcs = ["useless_assert_removal_pass_test.cc"],
    deps = [
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        ":useless_assert_removal_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "useless_io_removal_pass_test",
    srcs = ["useless_io_removal_pass_test.cc"],
    deps = [
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        ":useless_io_removal_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "comparison_simplification_pass_test",
    srcs = ["comparison_simplification_pass_test.cc"],
    deps = [
        ":comparison_simplification_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "conditional_specialization_pass_test",
    srcs = ["conditional_specialization_pass_test.cc"],
    # Stack usage is high with BDDs, disabling the stack limit during fuzzing seems necessary.
    args = ["--fuzztest_stack_limit_kb=0"],
    deps = [
        ":conditional_specialization_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "sparsify_select_pass_test",
    srcs = ["sparsify_select_pass_test.cc"],
    deps = [
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        ":sparsify_select_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "dataflow_visitor_test",
    srcs = ["dataflow_visitor_test.cc"],
    deps = [
        ":dataflow_visitor",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:source_location",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

xls_pass(
    name = "channel_legalization_pass",
    srcs = ["channel_legalization_pass.cc"],
    hdrs = ["channel_legalization_pass.h"],
    pass_class = "ChannelLegalizationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":token_provenance_analysis",
        "//xls/codegen/vast",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:function_builder",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:proc_elaboration",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_translator",
        "//xls/solvers:z3_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:compare",
        "@com_google_absl//absl/types:span",
        "@z3//:api",
    ],
)

xls_pass(
    name = "basic_simplification_pass",
    srcs = ["basic_simplification_pass.cc"],
    hdrs = ["basic_simplification_pass.h"],
    pass_class = "BasicSimplificationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":stateless_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_test(
    name = "basic_simplification_pass_test",
    srcs = ["basic_simplification_pass_test.cc"],
    deps = [
        ":basic_simplification_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "channel_legalization_pass_test",
    srcs = ["channel_legalization_pass_test.cc"],
    deps = [
        ":channel_legalization_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/interpreter:channel_queue",
        "//xls/interpreter:interpreter_proc_runtime",
        "//xls/interpreter:serial_proc_runtime",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:function_builder",
        "//xls/ir:ir_parser",
        "//xls/ir:proc_elaboration",
        "//xls/ir:value",
        "//xls/ir:verifier",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "minimal_feedback_arcs",
    srcs = ["minimal_feedback_arcs.cc"],
    hdrs = ["minimal_feedback_arcs.h"],
    deps = [
        ":token_provenance_analysis",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/log:vlog_is_on",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "node_source_analysis",
    hdrs = ["node_source_analysis.h"],
    deps = [
        ":dataflow_visitor",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:type",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

xls_pass(
    name = "dataflow_simplification_pass",
    srcs = ["dataflow_simplification_pass.cc"],
    hdrs = ["dataflow_simplification_pass.h"],
    pass_class = "DataflowSimplificationPass",
    deps = [
        ":node_source_analysis",
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:type",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "dataflow_simplification_pass_test",
    srcs = ["dataflow_simplification_pass_test.cc"],
    deps = [
        ":dataflow_simplification_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "minimal_feedback_arcs_test",
    srcs = ["minimal_feedback_arcs_test.cc"],
    deps = [
        ":minimal_feedback_arcs",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@google_benchmark//:benchmark",
        "@googletest//:gtest",
    ],
)

xls_pass(
    name = "next_value_optimization_pass",
    srcs = ["next_value_optimization_pass.cc"],
    hdrs = ["next_value_optimization_pass.h"],
    pass_class = "NextValueOptimizationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        "//xls/common:math_util",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "next_value_optimization_pass_test",
    srcs = ["next_value_optimization_pass_test.cc"],
    deps = [
        ":next_value_optimization_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "bit_provenance_analysis",
    srcs = ["bit_provenance_analysis.cc"],
    hdrs = ["bit_provenance_analysis.h"],
    deps = [
        ":dataflow_visitor",
        ":query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:type",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "bit_provenance_analysis_test",
    srcs = ["bit_provenance_analysis_test.cc"],
    deps = [
        ":bit_provenance_analysis",
        ":query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

xls_pass(
    name = "proc_state_provenance_narrowing_pass",
    srcs = ["proc_state_provenance_narrowing_pass.cc"],
    hdrs = ["proc_state_provenance_narrowing_pass.h"],
    pass_class = "ProcStateProvenanceNarrowingPass",
    deps = [
        ":bit_provenance_analysis",
        ":lazy_ternary_query_engine",
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:inline_bitmap",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:state_element",
        "//xls/ir:ternary",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "proc_state_provenance_narrowing_pass_test",
    srcs = ["proc_state_provenance_narrowing_pass_test.cc"],
    deps = [
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        ":proc_state_optimization_pass",
        ":proc_state_provenance_narrowing_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_parser",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/log:globals",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

xls_pass(
    name = "lut_conversion_pass",
    srcs = ["lut_conversion_pass.cc"],
    hdrs = ["lut_conversion_pass.h"],
    pass_class = "LutConversionPass",
    deps = [
        ":dataflow_graph_analysis",
        ":lazy_ternary_query_engine",
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":stateless_query_engine",
        ":union_query_engine",
        "//xls/common:math_util",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:ternary",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:fixed_array",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "lut_conversion_pass_test",
    srcs = ["lut_conversion_pass_test.cc"],
    deps = [
        ":lut_conversion_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

xls_pass(
    name = "array_untuple_pass",
    srcs = ["array_untuple_pass.cc"],
    hdrs = ["array_untuple_pass.h"],
    pass_class = "ArrayUntuplePass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:union_find",
        "//xls/ir",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:state_element",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:vlog_is_on",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

cc_test(
    name = "array_untuple_pass_test",
    srcs = ["array_untuple_pass_test.cc"],
    deps = [
        ":array_untuple_pass",
        ":dataflow_simplification_pass",
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "//xls/ir:value_builder",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

xls_pass(
    name = "non_synth_separation_pass",
    srcs = ["non_synth_separation_pass.cc"],
    hdrs = ["non_synth_separation_pass.h"],
    pass_class = "NonSynthSeparationPass",
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:channel",
        "//xls/ir:name_uniquer",
        "//xls/ir:node_util",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:state_element",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

cc_test(
    name = "non_synth_separation_pass_test",
    srcs = ["non_synth_separation_pass_test.cc"],
    deps = [
        ":dce_pass",
        ":non_synth_separation_pass",
        ":optimization_pass",
        ":pass_base",
        ":pass_test_helpers",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/interpreter:interpreter_proc_runtime",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_matcher",
        "//xls/ir:ir_test_base",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "proc_state_range_query_engine",
    srcs = ["proc_state_range_query_engine.cc"],
    hdrs = ["proc_state_range_query_engine.h"],
    deps = [
        ":back_propagate_range_analysis",
        ":dataflow_visitor",
        ":node_dependency_analysis",
        ":predicate_state",
        ":query_engine",
        ":range_query_engine",
        ":ternary_query_engine",
        ":union_query_engine",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "//xls/ir:interval",
        "//xls/ir:interval_ops",
        "//xls/ir:interval_set",
        "//xls/ir:op",
        "//xls/ir:state_element",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "proc_state_range_query_engine_test",
    srcs = ["proc_state_range_query_engine_test.cc"],
    deps = [
        ":proc_state_range_query_engine",
        ":range_query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:channel",
        "//xls/ir:channel_ops",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "aliasing_query_engine",
    hdrs = ["aliasing_query_engine.h"],
    deps = [
        ":predicate_state",
        ":query_engine",
        "//xls/common/status:ret_check",
        "//xls/data_structures:leaf_type_tree",
        "//xls/data_structures:union_find_map",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:interval_set",
        "//xls/ir:ternary",
        "//xls/ir:value",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "aliasing_query_engine_test",
    srcs = ["aliasing_query_engine_test.cc"],
    deps = [
        ":aliasing_query_engine",
        ":stateless_query_engine",
        "//xls/common:xls_gunit_main",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "@com_google_absl//absl/status:status_matchers",
        "@cppitertools",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "folding_graph_test",
    srcs = ["folding_graph_test.cc"],
    deps = [
        ":folding_graph",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "resource_sharing_pass_test",
    srcs = ["resource_sharing_pass_test.cc"],
    deps = [
        ":bdd_query_engine",
        ":node_dependency_analysis",
        ":optimization_pass",
        ":pass_base",
        ":query_engine",
        ":resource_sharing_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/interpreter:ir_interpreter",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:events",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/ir:source_location",
        "//xls/ir:value",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "select_lifting_pass_test",
    srcs = ["select_lifting_pass_test.cc"],
    deps = [
        ":dce_pass",
        ":optimization_pass",
        ":pass_base",
        ":select_lifting_pass",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/estimators/delay_model:delay_estimator",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:op",
        "//xls/solvers:z3_ir_equivalence_testutils",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "query_engine_helpers",
    hdrs = ["query_engine_helpers.h"],
    deps = [
        ":query_engine",
        "//xls/common:visitor",
    ],
)

cc_library(
    name = "pass_test_helpers",
    testonly = True,
    hdrs = ["pass_test_helpers.h"],
    deps = [
        ":optimization_pass",
        ":pass_base",
        "//xls/common/status:status_macros",
        "//xls/ir",
        "@com_google_absl//absl/base:nullability",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "bit_count_query_engine",
    srcs = ["bit_count_query_engine.cc"],
    hdrs = ["bit_count_query_engine.h"],
    deps = [
        ":dataflow_visitor",
        ":lazy_query_engine",
        ":query_engine",
        ":stateless_query_engine",
        "//xls/common:math_util",
        "//xls/common:source_location",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:interval_ops",
        "//xls/ir:interval_set",
        "//xls/ir:ternary",
        "//xls/ir:type",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/types:span",
        "@cppitertools",
    ],
)

cc_test(
    name = "bit_count_query_engine_test",
    srcs = ["bit_count_query_engine_test.cc"],
    deps = [
        ":bit_count_query_engine",
        ":query_engine",
        ":ternary_query_engine_test_common",
        "//xls/common:xls_gunit_main",
        "//xls/common/fuzzing:fuzztest",
        "//xls/common/status:matchers",
        "//xls/data_structures:leaf_type_tree",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_domain",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/fuzzer/ir_fuzzer:query_engine_helpers",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:interval",
        "//xls/ir:interval_set",
        "//xls/ir:ir_parser",
        "//xls/ir:ir_test_base",
        "//xls/ir:ternary",
        "//xls/ir:value",
        "//xls/ir:value_builder",
        "//xls/solvers:z3_ir_translator",
        "//xls/solvers:z3_ir_translator_matchers",
        "@com_google_absl//absl/strings",
        "@googletest//:gtest",
    ],
)

pytype_strict_binary(
    name = "bit_count_query_engine_proofs_z3",
    srcs = ["bit_count_query_engine_proofs_z3.py"],
    deps = [
        "@abseil-py//absl:app",
        "@abseil-py//absl/flags",
        requirement("z3-solver"),
    ],
)

cc_library(
    name = "ternary_query_engine_test_common",
    testonly = True,
    hdrs = ["ternary_query_engine_test_common.h"],
    deps = [
        ":query_engine",
        "//xls/fuzzer/ir_fuzzer:ir_fuzz_test_library",
        "//xls/fuzzer/ir_fuzzer:query_engine_helpers",
        "//xls/ir",
        "//xls/ir:ternary",
        "//xls/ir:value",
        "//xls/ir:value_utils",
        "@cppitertools",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "data_flow_node_info",
    hdrs = ["data_flow_node_info.h"],
    deps = [
        ":lazy_dag_cache",
        ":lazy_node_data",
        ":lazy_node_info",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:op",
        "//xls/ir:type",
        "//xls/ir:value",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "data_flow_node_info_test",
    srcs = ["data_flow_node_info_test.cc"],
    deps = [
        ":data_flow_node_info",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/data_structures:leaf_type_tree",
        "//xls/ir",
        "//xls/ir:bits",
        "//xls/ir:function_builder",
        "//xls/ir:ir_test_base",
        "//xls/ir:value",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)
